/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */
package org.ipig.commons.context;

import org.ipig.commons.helper.AssertHelper;
import org.ipig.commons.helper.StringHelper;
import org.ipig.constants.HadoopCnst;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

/**
 * HadoopContext
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id: HadoopContext.java 3 2020-01-21 09:36:33Z ts <comchnts@163.com> $$
 * @since 1.0
 */
public class HadoopContext {


    /**
     * getHadoopConfDir
     *
     * @return
     */
    public static String getHadoopConfDir() {
        String confDir = System.getenv(HadoopCnst.ENV_HADOOP_CONF_DIR);
        if (StringUtils.isBlank(confDir)) {
            confDir = StringHelper.join(File.separator, getHadoopHome(), "etc", "hadoop");
        }
        return confDir;
    }

    /**
     * getHadoopHome
     *
     * @return
     */
    public static String getHadoopHome() {
        String hadoopHome = System.getenv(HadoopCnst.ENV_HADOOP_HOME);
        AssertHelper.hasText(hadoopHome, "Set the HADOOP_HOME environment variable!");
        return hadoopHome;
    }
}
